<?php

function get_mubiao_overtime($type, $time = NULL) {
  $time = $time ? $time : time();
  $timeStamp = strtotime($time);
  switch ($type) {
    case 1:
      $weekday = date('w', $timeStamp);
      if ($weekday == 4) {
        return date('Y-m-d 16:00:00', $timeStamp);
      } elseif ($weekday > 4) {
        $minus = $weekday - 4;

        return date('Y-m-d 16:00:00', strtotime($minus . ' days', $timeStamp));
      } else {
        $minus = 4 - $weekday;

        return date('Y-m-d 16:00:00', strtotime($minus . ' days', $timeStamp));

      }

      break;
    case 2:
      return date('Y-m-25 16:00:00', $timeStamp);
      break;
    case 3:
      $nextMonth = date('Y-m-1', strtotime('+1 month', $timeStamp));

      return date('Y-m-d 17:00:00', strtotime('-1 day', strtotime($nextMonth)));

      break;
  }
}